package com.loyal.loyalerp.basedata.employeechange.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.loyal.loyalerp.basedata.department.mapper.DepartmentMapper;
import com.loyal.loyalerp.basedata.employeechange.mapper.GyPersonChangeMapper;
import com.loyal.loyalerp.basedata.employeechange.model.GyPersonChange;
import com.loyal.loyalerp.basedata.employeechange.service.PersonChangeService;
import com.loyal.loyalerp.basedata.person_predept.mapper.GyPersonPredeptMapper;
import com.loyal.loyalerp.mapper.GyPersonMapper;
import com.loyal.loyalerp.model.GyPerson;

@Service
public class PersonChangeServiceImpl implements PersonChangeService {
	@Autowired
	GyPersonChangeMapper personChangeDao;
	@Autowired
	GyPersonMapper personMapper;
	@Autowired
	GyPersonPredeptMapper personPredeptMapper;
	@Autowired
	DepartmentMapper departmentMapper;

	@Override
	public List<GyPersonChange> getAllPersonChanges() {
		return personChangeDao.selectByExample(null);
	}

	@Override
	public boolean addPersonChange(GyPersonChange personChange) {
		int num = personChangeDao.insert(personChange);
		if (0 == num)
			return false;
		else
			return true;
	}

	@Override
	public String getDepartmentNameByUserId(int userId) {
		long personId = personMapper.selectPersonIdByUserId(userId);
		GyPerson person = personMapper.selectByPrimaryKey(personId);
		if (person != null)
			return departmentMapper.selectDeptnameByPrimaryKey(person.getDeptid());
		else
			return null;
	}

	@Override
	public String getDepartmentNameByPersonId(long personId) {
		GyPerson person = personMapper.selectByPrimaryKey(personId);
		if (person != null)
			return departmentMapper.selectDeptnameByPrimaryKey(person.getDeptid());
		else
			return null;
	}

	@Override
	public boolean deletePersonChange(Integer personChangeId) {
		int num = personChangeDao.deleteByPrimaryKey(personChangeId);
		if (0 == num)
			return false;
		else
			return true;
	}

	@Override
	public boolean updatePersonChange(GyPersonChange personChange) {
		int num = personChangeDao.updateByPrimaryKeySelective(personChange);
		if (0 == num)
			return false;
		else
			return true;
	}
}
